package com.hao.springcloud.controller;

import com.hao.springcloud.entities.CommonResult;
import com.hao.springcloud.entities.Payment;
import com.hao.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author 97472
 * @version 1.0
 * @date 2022/1/4 16:10
 */
@RestController
@RequestMapping("/payment/")
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private Integer port;

    @PostMapping("add")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        int result = paymentService.add(payment);
        log.info("***插入结果："+result);
        CommonResult commonResult = result > 0?
                new CommonResult(200,"插入数据成功"+port):
                new CommonResult(444,"插入数据失败");
        return commonResult;
    }

    @GetMapping("get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("***查询结果："+payment);
        CommonResult commonResult = payment != null?
                new CommonResult(200,"查询成功"+port,payment):
                new CommonResult(444,"查询失败");
        return commonResult;
    }

    @GetMapping("get")
    public CommonResult get(){
        return new CommonResult();
    }
}
